<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : !disabled ? '修改' : '查看'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="120px">
      <el-col :span="12">
        <el-form-item label="" prop="project">
          <el-input v-model="dataForm.project" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="product">
          <el-input v-model="dataForm.product" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="injection">
          <el-input v-model="dataForm.injection" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="identify">
          <el-input v-model="dataForm.identify" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="branch">
          <el-input v-model="dataForm.branch" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="module">
          <el-input v-model="dataForm.module" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="execution">
          <el-input v-model="dataForm.execution" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="plan">
          <el-input v-model="dataForm.plan" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="story">
          <el-input v-model="dataForm.story" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="storyversion">
          <el-input v-model="dataForm.storyversion" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="task">
          <el-input v-model="dataForm.task" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="totask">
          <el-input v-model="dataForm.totask" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="tostory">
          <el-input v-model="dataForm.tostory" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="title">
          <el-input v-model="dataForm.title" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="keywords">
          <el-input v-model="dataForm.keywords" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="severity">
          <el-input v-model="dataForm.severity" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="pri">
          <el-input v-model="dataForm.pri" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="type">
          <el-input v-model="dataForm.type" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="os">
          <el-input v-model="dataForm.os" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="browser">
          <el-input v-model="dataForm.browser" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="hardware">
          <el-input v-model="dataForm.hardware" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="found">
          <el-input v-model="dataForm.found" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="steps">
          <el-input v-model="dataForm.steps" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="status">
          <el-input v-model="dataForm.status" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="substatus">
          <el-input v-model="dataForm.substatus" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="color">
          <el-input v-model="dataForm.color" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="confirmed">
          <el-input v-model="dataForm.confirmed" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="activatedcount">
          <el-input v-model="dataForm.activatedcount" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="activateddate">
          <el-input v-model="dataForm.activateddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="feedbackby">
          <el-input v-model="dataForm.feedbackby" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="notifyemail">
          <el-input v-model="dataForm.notifyemail" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="mailto">
          <el-input v-model="dataForm.mailto" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="openedby">
          <el-input v-model="dataForm.openedby" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="openeddate">
          <el-input v-model="dataForm.openeddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="openedbuild">
          <el-input v-model="dataForm.openedbuild" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="assignedto">
          <el-input v-model="dataForm.assignedto" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="assigneddate">
          <el-input v-model="dataForm.assigneddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="deadline">
          <el-input v-model="dataForm.deadline" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="resolvedby">
          <el-input v-model="dataForm.resolvedby" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="resolution">
          <el-input v-model="dataForm.resolution" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="resolvedbuild">
          <el-input v-model="dataForm.resolvedbuild" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="resolveddate">
          <el-input v-model="dataForm.resolveddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="closedby">
          <el-input v-model="dataForm.closedby" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="closeddate">
          <el-input v-model="dataForm.closeddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="duplicatebug">
          <el-input v-model="dataForm.duplicatebug" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="linkbug">
          <el-input v-model="dataForm.linkbug" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="case">
          <el-input v-model="dataForm.case" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="caseversion">
          <el-input v-model="dataForm.caseversion" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="feedback">
          <el-input v-model="dataForm.feedback" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="result">
          <el-input v-model="dataForm.result" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="repo">
          <el-input v-model="dataForm.repo" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="mr">
          <el-input v-model="dataForm.mr" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="entry">
          <el-input v-model="dataForm.entry" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="lines">
          <el-input v-model="dataForm.lines" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="v1">
          <el-input v-model="dataForm.v1" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="v2">
          <el-input v-model="dataForm.v2" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="repotype">
          <el-input v-model="dataForm.repotype" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="issuekey">
          <el-input v-model="dataForm.issuekey" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="testtask">
          <el-input v-model="dataForm.testtask" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="lasteditedby">
          <el-input v-model="dataForm.lasteditedby" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="lastediteddate">
          <el-input v-model="dataForm.lastediteddate" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="" prop="deleted">
          <el-input v-model="dataForm.deleted" :disabled="disabled" :maxlength="100" placeholder=""></el-input>
        </el-form-item>
      </el-col>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      disabled: false,
      visible: false,
      dataForm: {
        id: '',
        project: '',
        product: '',
        injection: '',
        identify: '',
        branch: '',
        module: '',
        execution: '',
        plan: '',
        story: '',
        storyversion: '',
        task: '',
        totask: '',
        tostory: '',
        title: '',
        keywords: '',
        severity: '',
        pri: '',
        type: '',
        os: '',
        browser: '',
        hardware: '',
        found: '',
        steps: '',
        status: '',
        substatus: '',
        color: '',
        confirmed: '',
        activatedcount: '',
        activateddate: '',
        feedbackby: '',
        notifyemail: '',
        mailto: '',
        openedby: '',
        openeddate: '',
        openedbuild: '',
        assignedto: '',
        assigneddate: '',
        deadline: '',
        resolvedby: '',
        resolution: '',
        resolvedbuild: '',
        resolveddate: '',
        closedby: '',
        closeddate: '',
        duplicatebug: '',
        linkbug: '',
        case: '',
        caseversion: '',
        feedback: '',
        result: '',
        repo: '',
        mr: '',
        entry: '',
        lines: '',
        v1: '',
        v2: '',
        repotype: '',
        issuekey: '',
        testtask: '',
        lasteditedby: '',
        lastediteddate: '',
        deleted: ''
      },
      dataRule: {
        name: [
          {required: true, message: '名称不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    init(id, disabled) {
      this.disabled = disabled
      this.dataForm.id = id || ''
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: `/zt/bug/info/${this.dataForm.id}`,
            method: 'get'
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm = data.bug
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm']
        .validate((valid) => {
          if (valid) {
            this.$http({
              url: `/zt/bug/${!this.dataForm.id ? 'save' : 'update'}`,
              method: 'post',
              data: this.dataForm
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500
                })
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          }
        })
    }
  }
}
</script>
